package com.example.zhaoping.controller;

import com.example.zhaoping.entity.Admin;
import com.example.zhaoping.serviceImpl.AdminServiceImpl;
import com.example.zhaoping.util.Result;
import com.example.zhaoping.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private Result result;
    @Resource
    private AdminServiceImpl adminService;

    @GetMapping(value = "/getMenu",name = "权限")
    public Result<?> getMenu(@RequestHeader("Authorization") String token){

        return result.success();
    }

    @GetMapping(value = "get_admin",name = "获取管理员信息")
    public Result getAdmin(@RequestHeader("Authorization") String token){
        int id = TokenUtil.getUserId(token);
        Admin admin = adminService.selectAdminById(id);
        if(admin != null){
            return result.success(admin);
        }else {
            return result.error("获取管理员信息失败！");
        }
    }
    public Result getData(){
        return result.success();
    }
}
